<i><%@page language="java" import="java.util.*" pageEncoding="UTF-8"%>
	<!DOCTYPE html>
	<html>
<head>
<meta charset="UTF-8">
<title>资讯 编辑页面</title>
<meta
	content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
	name="viewport">
<jsp:include page="../com/header.jsp"></jsp:include>
<script type="text/javascript" src="../../js/comm/editcomm.js"></script>
<script type="text/javascript">
		$(function(){
			$("#saveOrupdate").click(function(){
				$("#thumbnail").val(imgUrl);
				if (!$('#newsContent').find('#myImageShow').attr("src")) {
					myAlert("请上传图片");
					return;
				}
				saveData(root + 'cms/news/saveNews','newsList.jsp');
			});
			var tId = getUrlParam("id");
			if (!tId) {
				myAlert('id参数不能为空');
                getCategories("");
				return;
			}
			$.ajax({
				url : root + 'cms/news/findNewsById',
				type : 'post',
				dataType : 'json',
				data : {
					modelId : tId
				},
				success : function(data) {
					console.log(data);
					if (data.code == 1) {
						var contentHtml = $('#newsTmpl').render(
								data.object, {
									mydata : data
								});
						$('#newsContent').html(contentHtml);
						ue = UE.getEditor("content");
						ue.addListener("ready", function() {
							if (data.object.content)
								ue.setContent(data.object.content);
						});
                        //获取类别
                        getCategories(data.object.type);
					} else {
						var contentHtml = $('#newsTmpl').render("");
						$('#newsContent').html(contentHtml);
						//获取类别
                        getCategories(data.object.type);
					}
				}
			});
			//上传图片
			$('#newsContent').on('click','#uploadPhotoFile', function () {
				upload("news");
	        });
		});

        //获取商品分类
        function getCategories(objid) {
            $.ajax({
                url: root + "cms/category/findShopCategoryNEStatusPage",
                data: {
                    nextPage: 0,
                    pageSize: 99999,
                    sortData: null,
                    jsonFilter:"{'search_EQ_type':'2'}"
                },
                type: 'POST',
                timeout: 7000,
                dataType: 'json'
            }).done(function (data) {
                if (data.code == 1) {
                    var _html = "<option value='' selected>请选择</option>";
                    for (var i = 0; i < data.object.content.length; i++) {
                        if (objid == data.object.content[i].id) {
                            _html += "<option value='" + data.object.content[i].id + "' selected>" + data.object.content[i].categoryName + "</option>";
                        } else {
                            _html += "<option value='" + data.object.content[i].id + "'>" + data.object.content[i].categoryName + "</option>";
                        }
                    }
                    $("#newsType").html(_html);

                    if (data.object.content <= 0) {
                        //没有分类数据，提示去添加
                        myConfirm("没有咨询分类，无法添加咨询，请先去添加？", function () {
                            location.href = "../category/categoryList.jsp";
                        })
                    }
                } else {
                    myAlert(data.message || tipMessage.undefined_msg);
                }
            }).fail(function (jqXHR, textStatus, errorThrown) {
                if (textStatus == "timeout") {
                    myAlert(tipMessage.timeout_msg);
                } else {
                    myAlert(tipMessage.error_msg);
                }
            });
        }

</script>
</head>
<body>
	<section>
		<div>
			<div class="col-xs-12">
				<div class="box" style="height:900px">
					<div class="box-header">
						<br> <input type="button" value="确定" id="saveOrupdate"
							class="btn btn-success">
						<input type="button" onclick="backAction('newsList.jsp');" class="btn btn-info" value="返回"/>

					</div>
					<form id="submit_form" class="form-horizontal">
						<div class="tab" id="newsContent"></div>
					</form>
				</div>
			</div>
		</div>
	</section>
	<script type="text/x-jsrender" id="newsTmpl">
			<fieldset> 
				<input type="hidden" id="tId" name="id" value="{{:id}}" />
	        	{{!--<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">图片：</label>
       				 <div class="col-md-3">
						<div class="upload_div">
                        	<img id="myImageShow" src="../../{{:imgUrl}}" width="100px" height="100px" />
                        	<input type="hidden" id="imgUrl" name="imgUrl" value="{{:imgUrl}}"/>
                        	<input type="file" id="uploadPhotoFile" name="photoFile" class="upload_file">
                        </div>
					</div>
      			</div>--}}
				<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">标题：</label>
       				 <div class="col-md-3">
						<input type="text" placeholder="请填写标题" class="form-control input-sm" data-rule="required;length[0~100]" id="title" name="title" value="{{:title}}" />
					</div>
      			</div>
      			<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">类型：</label>
       				 <div class="col-md-4">
       				    <select name="type" id="newsType"  data-rule="required" class="form-control input-sm"></select>
					</div>
      			</div>
				<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">资讯来源：</label>
       				 <div class="col-md-3">
						<input type="text" placeholder="请填写资讯来源" class="form-control input-sm" data-rule="required;length[0~50]" id="source" name="source" value="{{:source}}" />
					</div>
      			</div>
				<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">资讯缩略图：</label>
					<div class="col-md-3">
						<div class="upload_div">
                        	<img id="myImageShow" src="../../{{:thumbnail}}" width="100px" height="100px" />
                        	<input type="hidden" id="thumbnail" name="thumbnail" value="{{:thumbnail}}"/>
                        	<input type="file" id="uploadPhotoFile" name="photoFile" class="upload_file">
                        </div>
					</div>
      			</div>
				<%--<div class="form-group">--%>
        			<%--<label class="col-md-2 control-label controls" for="formGroupInputSmall">是否热点：</label>--%>
       				 <%--<div class="col-md-3">--%>
						<%--<select class="form-control input-sm" id="isHot" name="isHot" data-rule="required" >--%>
                          <%--<option  value="">请选择</option>--%>
                          <%--<option  value="1" {{if isHot=="1"}}selected{{/if}}>是</option>--%>
                          <%--<option  value="0" {{if isHot=="0"}}selected{{/if}}>否</option>--%>
                        <%--</select>	--%>
					<%--</div>--%>
      			<%--</div>--%>
				<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">内容：</label>
			 		<div class="col-md-9" id="content" name="content" style="height:200px;"></div>			
      			</div>
			</fieldset>
	</script>
</body>
	</html></i>